package controllers;

import view.V_Tooltip;

///////////////////////////
//TOOLTIP CONTROLLER
//tooltip controller's current focus is to update the tooltip's location. It will also set it to invisible if a button was clicked
public class C_TooltipControl extends C_Control {
	V_Tooltip V_tooltip;
	int edgePad = 3;
	int mouseWidth = 15;
	float tempX, tempY;
	final int delay = 5;
	private int checks = 0;

	public C_TooltipControl(V_Tooltip V_tTip, ControlManager cManager) {
		vFeature = V_tTip;
		V_tooltip = V_tTip;
		V_tooltip.setController(this);
		controlManager = cManager;
		controlManager.addController(this);// it adds itself to the controlManager of the scene
		priority = 20.0f;
	}

	@Override
	public void onInteract(float mouseXLoc, float mouseYLoc, String interID) {

		float tempX = 0;
		float tempY = 0;

		if (interID.equals("") == false) // if the mouse isn't realeased, then
											// the tooltip should not be active
		{
			active = false;
		}

		// if the tooltip is too close to an edge of the screen it should be
		// bumped in certain ways either down and/or to the left
		if (mouseXLoc >= V_tooltip.getParent().width - V_tooltip.getXSize() - edgePad) {
			tempX = V_tooltip.getXSize();
			tempX *= -1;
		}
		if (mouseYLoc <= V_tooltip.getXSize() - edgePad) {
			tempY = V_tooltip.getYSize();
		}
		if (tempX == 0) {
			tempX = mouseWidth;
		}

		// after preforming transformations apply them to the tooltip if any exist
		V_tooltip.setFlip(tempX, tempY);
		V_tooltip.setLocation(mouseXLoc, mouseYLoc); // location is always set near the mouse
		V_tooltip.setVisibility(active);
	}

	public boolean checkForTip(float mouseXLoc, float mouseYLoc) {
		// This set of algorithms will enable tooltips if the correct amount of time has passed:
		if (checks <= 0) {
			tempX = mouseXLoc;
			tempY = mouseYLoc;
		}

		if (mouseXLoc == tempX && mouseYLoc == tempY) {
			checks++;
		} else
			checks = 0;

		if (checks >= delay) {
			return true;
		} else
			return false;
	}
	
	public void setName(String n) { // pass this method along to the tooltip view component
		V_tooltip.setName(n);
	}
}// end of tooltip controller
